﻿Imports Microsoft.VisualBasic
Imports System.Data

<System.ComponentModel.DataObjectAttribute(True)> _
Public Class BLL_Award

    Public Sub New()
        ' 
        ' TODO: 在此加入建構函式的程式碼 
        ' 
    End Sub

    'SELECT 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.[Select])> _
    Public Function BLL_Select(ByVal AwardID As Integer) As DataTable

        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("SELECT * ")
        sql.AppendFormat("FROM Award ")
        sql.AppendFormat("WHERE AwardID={0}", AwardID)

        Return dat.GetData(sql)

    End Function

    'Insert
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert)> _
    Public Function BLL_Insert(ByVal AwardName As String, ByVal Annual As Integer, ByVal Description As String, ByVal CreateBy As String) As Integer
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Using scope As New Transactions.TransactionScope

            sql.Length = 0

            sql.AppendFormat("insert Award (AwardName,Annual,Description,CreateDate,CreateBy) select ")
            sql.AppendFormat(" '{0}' ", AwardName)
            sql.AppendFormat(",{0} ", Annual)
            sql.AppendFormat(",'{0}' ", Description)
            sql.AppendFormat(",getdate() ")
            sql.AppendFormat(",'{0}' ", CreateBy)

            sql.AppendFormat("UPDATE AwardRecord SET AwardID=@@IDENTITY  WHERE AwardID=0 and CreateBy='{0}';", CreateBy)

            dat.AccData(sql)

            scope.Complete()
            '
            Return 1

        End Using

    End Function

    'Update 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update)> _
       Public Function BLL_Update(ByVal AwardName As String, ByVal Annual As Integer, ByVal Description As String, ByVal CreateBy As String, ByVal original_AwardID As Integer) As Integer

        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Using scope As New Transactions.TransactionScope

            sql.AppendFormat("UPDATE Award ")
            sql.AppendFormat("SET AwardName='{0}' ", AwardName)
            sql.AppendFormat(",Annual={0} ", Annual)
            sql.AppendFormat(",Description='{0}' ", Description)
            sql.AppendFormat(",CreateDate=getdate() ")
            sql.AppendFormat(",CreateBy='{0}' ", CreateBy)

            sql.AppendFormat("WHERE AwardID={0}; ", original_AwardID)

            dat.AccData(sql)

            scope.Complete()

            Return 1

        End Using

    End Function

End Class
